﻿namespace cludg.Services.Security
{
	public static class MembershipHelper
	{
		public static bool TryValidateUser(this IMembership membership, Principal principal, out string userId)
		{
			ValidateUserError error;
			return TryValidateUser(membership, principal, out userId, out error);
		}

		public static bool TryValidateUser(this IMembership membership, Principal principal, out string userId, out ValidateUserError error)
		{
			userId = string.Empty;
			error = null;
			try
			{
				userId = membership.ValidateUser(principal);
				return true;
			}
			catch (ValidateUserError e)
			{
				error = e;
				return false;
			}
		}
	}
}
